package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.busi.service.video.VideoService;
import com.cssw.fyzb.core.model.vo.video.FoundVideoByPhpVo;
import com.cssw.fyzb.core.model.vo.video.FoundVideoVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查询 发现 视频列表
 *
 * @author Feng Chen
 */
@Function(description = "查询 发现 视频列表", parameters = {
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = false),
        @Parameter(name = "pageNumber", type = Type.Integer, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.Integer, description = "页大小", required = true),
}, result = @Result(
        properties = {
                @Property(name = "total", type = Type.Integer, description = "总页数"),
                @Property(name = "count", type = Type.Integer, description = "总行数"),
        },
        listProperties = {
                @ListProperty(name = "list", properties = {
                        @Property(name = "userId", type = Type.Integer, description = "作者编号"),
                        @Property(name = "nickName", type = Type.Integer, description = "作者昵称"),
                        @Property(name = "avatar", type = Type.Integer, description = "作者头像"),
                        @Property(name = "vedioId", type = Type.Integer, description = "视频编号"),
                        @Property(name = "title", type = Type.Integer, description = "视频主题"),
                        @Property(name = "media", type = Type.Integer, description = "视频地址"),
                        @Property(name = "thumb", type = Type.Integer, description = "视频封面"),
                        @Property(name = "likes", type = Type.Integer, description = "点赞数"),
                        @Property(name = "views", type = Type.Integer, description = "浏览数"),
                        @Property(name = "comments", type = Type.Integer, description = "评论数"),
                        @Property(name = "shares", type = Type.Integer, description = "分享数"),
                        @Property(name = "createTime", type = Type.Integer, description = "创建时间"),
                })
        }
))
@Component
public class ListFoundByPhpVideo implements Action {

    @Autowired
    private VideoService videoService;

    private static final Logger logger = LoggerFactory.getLogger(ListFoundByPhpVideo.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        try {
            Page<FoundVideoByPhpVo> page = videoService.pageFoundByPhp(userId, pageNumber, pageSize);
            return Response.success().put("list", page.getList()).put("total", page.getTotalPage()).put("count", page.getTotalRow());
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
